home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d8 / tlxsrch.arc / SRCHDIR.SLT < prev   
Text File  |  1990-07-06  |  3KB  |  69 lines

  1. main()
  2. {
  3.    int dnum;
  4.  
  5.    dnum = dir_find("Starfleet","TELIX.FON");
  6.    if (dnum >= 0)
  7.       dial(dir_find("Starfleet","TELIX.FON"),0,0);
  8.    else
  9.       return (-1);
  10. }
  11.  
  12.  
  13. //////////////////////////  dir_find ()  /////////////////////////////////
  14. //   This function will search the directory specified in <fonlist> for
  15. // the entry specified in <key>.  A dummy directory called BLANK.FON is
  16. // necessary to force Telix to close the current dialing directory.
  17. //
  18. // Returns: the entry number if <key> found
  19. //          -1 if <key> not found
  20. //          -2 if dummy directory not there
  21. //          -3 if directory to search not there
  22. //          -4 if couldn't restore directory to search
  23. // Author:  Paul A. Billlings, Las Cruces, NM
  24. //          NM BBS # (505) 523-4528 Freeflight (summers)
  25. //          NC BBS # (919) 481-1864 Waterfront West
  26. str dir_find_num[5];                   // Make global so can return it
  27. dir_find(str key,str fonlist)
  28. {
  29.    int f,                              // Filehandle
  30.        n,                              // Number of entries
  31.        i;                              // Counter
  32.    str build[64],                      // Used to build filenames
  33.        buf[25];                        // Holds input name
  34.  
  35.    build = _telix_dir;                 // Build dummy directory name
  36.    strcat(build,"BLANK.FON");
  37.    if (!loadfon (build))               // Dummy file not there
  38.       return ("-2");
  39.  
  40.    f = fopen(fonlist, "r");            // File to search not there
  41.    if (!f)
  42.       return ("-3");
  43.  
  44.    fseek (f,6,0);                      // Number of entries
  45.    n = fgetc (f);                      //   Low order byte
  46.    n = n + 256*fgetc (f);              //   High order byte
  47.  
  48.    for (i = 0;i < n; i = i+1) {
  49.       fseek (f,i*86+64,0);             // Find next record location
  50.                                        //   Record len = 86 bytes
  51.                                        //   Header = 64 bytes
  52.       fgets (buf,25,f);                // Read name
  53.       if (strposi (buf,key,0) >= 0)    // Found it!
  54.          break;
  55.    }
  56.  
  57.    fclose (f);                         // Clean up
  58.    build = _telix_dir;
  59.    strcat(build,fonlist);              // Build dummy directory name
  60.    if (!loadfon (build))               // Can't restore directory
  61.       return ("-4");
  62.  
  63.    if (i==n) return (-1);              // Return status (-1==not found)
  64.  
  65.    itos(i+1,dir_find_num);             // Convert to character format
  66.    return (dir_find_num);              //   for use by dial()
  67. }
  68.  
  69.